import {
  Component,
  Injector,
  ViewEncapsulation,
  ViewChild,
  OnInit,
} from "@angular/core";
import { AppComponentBase } from "@shared/common/app-component-base";
import {
  MaterialOutServiceProxy,
  PipelineListDto,
  MaterialOutAndReturnListDto,
  MaterialReturnServiceProxy,
} from "@shared/service-proxies/service-proxies";

@Component({
  selector: "yl10",
  templateUrl: "./yl10.component.html",
  styleUrls: ["./yl10.component.less"],
  encapsulation: ViewEncapsulation.None,
})
export class YL10ModalComponent extends AppComponentBase implements OnInit {
  subTaskCode = "";
  drawingCode = "";

  saving = false;
  isLoading = false;

  filterText = "";

  pipe: PipelineListDto = new PipelineListDto();

  outs = new Array<MaterialOutAndReturnListDto>();

  //table cols
  cols: any[];
  selectedColumns: any[];
  expandedRowKeys = [];

  constructor(
    injector: Injector,
    private _outMaterialServiceProxy: MaterialOutServiceProxy,
    private _returnMaterialServiceProxy: MaterialReturnServiceProxy
  ) {
    super(injector);
  }

  ngOnInit(): void {
    this.cols = [
      {
        field: "taskCode",
        header: "任务号",
        width: "150px",
        isDefaultSelect: true,
      },
      {
        field: "drawingCode",
        header: "图号",
        width: "120px",
        isDefaultSelect: true,
      },
      {
        field: "materialName",
        header: "名称",
        width: "100px",
        isDefaultSelect: true,
      },
      { field: "invFurBatch", header: "炉批号", width: "100px" },
      { field: "invCode", header: "质检编号", width: "100px" },
      {
        field: "paiHao",
        header: "牌号",
        width: "100px",
        isDefaultSelect: true,
      },
      {
        field: "hgzNo",
        header: "合格证",
        width: "100px",
        isDefaultSelect: true,
      },
      { field: "hgz_zjd", header: "物质编码", width: "100px" },
      { field: "materialStatus", header: "材料状态", width: "100px" },
      {
        field: "hgz_zyd",
        header: "质疑单号",
        width: "100px",
        isDefaultSelect: true,
      },
      { field: "materialSpec", header: "规格", width: "100px" },
      { field: "materialSize", header: "尺寸", width: "100px" },
      { field: "invMeasName", header: "计量单位", width: "100px" },
      { field: "techCondition", header: "技术状态", width: "100px" },
      { field: "zhuanYongInfo", header: "专料专用信息", width: "100px" },
    ];

    this.selectedColumns = this.cols.filter((el) => {
      return el.isDefaultSelect;
    });
  }

  load(pipe: PipelineListDto): void {
    this.pipe = pipe;

    this.getOuts();
  }

  getOuts() {
    this._outMaterialServiceProxy
      .getOutAndReturnWarehouseBills(this.pipe.id)
      .subscribe((result) => {
        this.outs = result.items;
        console.log(this.outs);
        this.outs.forEach((el) => {
          this.expandedRowKeys[el.id] = 1;
        });
      });
  }
  getClean(id: string) {
    this._returnMaterialServiceProxy
      .cleanReturnWarehouse(id)
      .subscribe((result) => {
        this.notify.success("撤销成功");
        this.getOuts();
      });
  }
  reloadPage(): void {
    this.getOuts();
  }
}
